<?php


/**
 * _parseParameterds
 * 分析从命令行传入的参数
 *
 * 支持的类型：
 * -e
 * -e <value>
 * --long-param
 * --long-param=<value>
 * --long-param <value>
 * <value>
 *
 * @return array
 */



try {
    echo "<pre>";
    var_dump($argv);
 
    $ctlName = '';
    for ($ai = 0; $ai < count($argv); ++ $ai) {
        if ($argv[$ai] == '-n' || $argv[$ai] == '--n') {
            $ctlName = $argv[$ai + 1];
        }
    }
    // 函数名称
    // $ctlName = 'bcSubNum';
    var_dump('-functionName-',$ctlName);
    // 参数
    $params = _parseParameterds();
    var_dump('=params=',$params);
    $prex = '_';
    $functionsName = $prex.''.$ctlName.'Action';
    echo '=$functionsName='.$functionsName;
    echo "\r\n";



    ///*
    try {
        $ret = $functionsName($params);
        // $ret = $this->$functionsName($params);
        var_dump($ret);

    } catch (Exception $e) {

        var_dump($e);
    }
    // ////////////////////end//////////////////////
} catch(Exception $e) {
    echo 'ERROR: ' . $e->getMessage();
    echo "\n";
    exit;
}

function _parseParameterds(){
    $result = array();
    $params = $GLOBALS['argv'];
    reset($params);
    // var_dump('=params=',$params);

    foreach ($params as $key => $value) {
        if($key ==0){
            continue;
        }

        $xcxDecorate=strpos($value,'-') === false?0:1;

        if(!empty($xcxDecorate)){
            $pname = substr($value, 1);
            $nextParm = isset($params[$key+1]) ?$params[$key+1]:'';
            if($nextParm === '' ){
                continue;
            }
            $result[$pname] = $nextParm;
        }


        // echo '=key=',$key,'=value=',$value,'=pname=',$pname,'=nextParm=',$nextParm;
        // echo "\r\n";

    }
    return $result;
}

function _bcSubNumAction($param){
    echo $param['n'].'----->>'.$param['bid'].'========>>'.$param['msg'];
    echo "\r\n";
    $ret = '_bcSubNumAction';
    return $ret;
}








